 class ifLogin{
	constructor(options){
		this.ologin = options.login,
		this.oregiest = options.regiest
		this.car = options.car
		this.myid = options.myid
		

//		this.url = options.url
	
	    this.load();
	    this.addEvent();
	}
	
	load(){
		var that = this;
		$.ajax({
			url:'api/user',
			type:'get',
			success:function(res){
				// console.log(res)
				if(res.error==0){
					that.myid.html(res.data.username)
					that.ologin.html("个人中心")
					that.oregiest.html('注销')
				}
				
			}
		})
		// console.log($.cookie("node_id"))
		// if($.cookie("node_id")){
		// 	this.ologin.html("个人中心")
		// 	this.oregiest.html("注销")
		// }
		
//		console.log(this.gd)
	}
	
	
	
	addEvent(){
		var that=this;
		var obj = $.cookie


		this.ologin.on("click",function(){
//			console.log(this.html())
			if($(this).html()=="请登录"){
//				console.log(111)
				location.href="l.html"
			}if($(this).html()=="个人中心"){
				location.href="car.html"
				
			}
		})
		
		this.oregiest.on("click",function(){
//			console.log($(this).html())
			if($(this).html()=="注册"){
				location.href="r.html"
			}if($(this).html()=="注销"){
				that.myid.html("")
				that.ologin.html("请登录")
				$(this).html("注册")
				$.ajax({
					url:'api/logout',
					type:'get',
					success:function(res){
						console.log(res)
					}
				})
			}
			
		})
		

		
		this.car.on("click",function(){
			$.ajax({url:'api/user',
			type:'get',
			success:function(res){
				if(res.error==0){
					location.href="car.html"
				}else{
					alert("请登录")
				}
				
			}
		})
			// if(obj("login")){
			// 	location.href="car.html"
			// }else{
			// 	alert("请登录")
			// }
		})
		
		
		
	}
	
	

	
}

new ifLogin({
	login:$("#login"),
	regiest:$("#regiest"),
	car:$(".car"),
	myid:$("#myid")
	
	
})